#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File: 			web.py
@Version: 		1.0
@Author: 		kztxt
@Email: 		kztxt@163.com
@CreatedAt: 	2025-09-30 10:36:42
'''

# here put the import lib
import io, os, sys

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append('{}/cosyvoice2'.format(ROOT_DIR))
sys.path.append('{}/cosyvoice2/Matcha-TTS'.format(ROOT_DIR))

from config.logger import setup_logging
from config.config import Config
from fastapi import FastAPI

from fastapi.middleware.cors import CORSMiddleware
import uvicorn

app = FastAPI(on_startup=[setup_logging])
# set cross region allowance
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"])

from webapi.cosyvoice import router as cosyvoice_router
app.include_router(cosyvoice_router, prefix="/to_speech", tags=["to_speech"])

if __name__ == '__main__':
    config = uvicorn.Config(app, host=Config.Host, port=Config.Port, log_level=None, workers=Config.Workers)
    server = uvicorn.Server(config)
    server.run()
